import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEActionVR } from './ipsdeaction-vr';
import { IPSDEField } from '../defield/ipsdefield';
import { IPSDEFValueRule } from '../defield/valuerule/ipsdefvalue-rule';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEActionVRImpl extends PSModelObjectImpl implements IPSDEActionVR {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue;
  }

  protected psdefvaluerule: IPSDEFValueRule | null = null;

  getPSDEFValueRule(): IPSDEFValueRule | null {
    if (this.psdefvaluerule != null) return this.psdefvaluerule;
    const value = this.M.getPSDEFValueRule;
    if (value == null) {
      return null;
    }
    this.psdefvaluerule = this.getPSDEFieldMust().findPSDEFValueRule(value);
    return this.psdefvaluerule;
  }

  get psDEFValueRule(): IPSDEFValueRule | null {
    return this.getPSDEFValueRule();
  }

  getPSDEFValueRuleMust(): IPSDEFValueRule {
    const value = this.getPSDEFValueRule();
    if (value == null) {
      throw new Error('未指定属性值规则');
    }
    return value;
  }

  protected psdefield: IPSDEField | null = null;

  getPSDEField(): IPSDEField | null {
    if (this.psdefield != null) return this.psdefield;
    const value = this.M.getPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psdefield = ipsdataentity.findPSDEField(value);
    }
    return this.psdefield;
  }

  get psDEField(): IPSDEField | null {
    return this.getPSDEField();
  }

  getPSDEFieldMust(): IPSDEField {
    const value = this.getPSDEField();
    if (value == null) {
      throw new Error('未指定属性对象');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get valueRuleType(): 'DEFVALUERULE' | 'SYSVALUERULE' {
    return this.M.valueRuleType;
  }

  get cls(): string {
    return 'PSDEActionVRImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.action.IPSDEActionVR') return true;
    return super.instanceof(cls);
  }
}
